(function($){
	// extending jquery object
	$.extend({
		lwData: {
			records: {},
			includeInner : true,
			speed: 'slow'
		},
		storageIDs: {
			records: 'wallet-records',
			commons: 'wallet-commons',
			max_id: 'wallet-max-id'
		},
		getReverseData: function() {
			var rev = [];
			for(var r in $.lwData.records) {
				rev.push(r);
			}
			return rev.reverse();
		}
	});
})(jQuery);

function storeData(data) {
	$.jStorage.set($.storageIDs.records, data);
}

function getData() {
	return $.jStorage.get($.storageIDs.records, undefined);
}

/*
function updateData(obj) {
	var index = getObjectIndex(obj);
	// if not NaN
	if(index) {
		return $.lwData.records.splice(index, 1, obj);
	}
	return index;
}

function getObjectIndex(obj) {
	var id = getIntID(obj);
	if(id) {
		for(var index = 0 ; index < $.lwData.records.length ; index++) {
			if(index == id) {
				return index;
			}
		}
	}
	return Number.NaN;
}*/

function getNextID() {
	// id : 'r_####'
	var form = 'r_';
	var curr = parseInt($.jStorage.get($.storageIDs.max_id, form+'1').split(form)[1]);
	if(curr) {
		curr++;
		return (form+curr);
	}
	return (from+1);
}

function getIntID(obj) {
	return parseInt(obj.id.split('r_')[1]);
}

function setNextID(max) {
	$.jStorage.set($.storageIDs.max_id, max)
}

// clears all locally stored data
function flush() {
	$.jStorage.flush();
}
